// app.js
App({
  onLaunch() {
    var that=this
    console.log(wx.getStorageSync('token'))
    if(wx.getStorageSync('token')){
      wx.request({
        url:`${this.globalData.url}/customer/user`,
        header:{'Authorization':wx.getStorageSync('token')},
        success:res=>{
          let userInfo=res.data[0]
          wx.setStorageSync('user',{
            userId:userInfo.userId,
            userName: userInfo.userName,
            sex: userInfo.sex,
            age: userInfo.age,
            head_Photo: userInfo.head_Photo
          })
          wx.switchTab({
            url: '/pages/home/home',
          })
        }
      })
    }else{
      //登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          console.log(res.code)
          wx.request({
            url:`${that.globalData.url}/customer/login/${res.code}`,
            dataType:'text',
            success:ret=>{
              
              wx.setStorageSync('token', ret.data)
              wx.navigateTo({
                url:'/pages/authorize/authorize'
              })
            }
          })
        }
      })
    }
  },
  globalData: {
    userInfo: null,
    url:'https://api.lzjlw.top:3030',
    // user:wx.getStorageSync('user'),
    talks_get:[],//保存从数据库里得到的数据 从数据库获取的数据
    mylist:[],//保存带下标的数据库所有动态
    inputValue_dy:'',//保存自己上传的动态的输入框中的内容
    dynamicId_get:'',//保存点击我是详情时的的动态id 以跳转到相应页面
  }
})
